package com.ruoyi.wgjlcData.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wgjlcData.domain.plat.DataWgjlcChwqd;
import com.ruoyi.wgjlcData.domain.vo.TestChwqd;
import com.ruoyi.wgjlcData.mapper.DataWgjlcChwqdMapper;
import com.ruoyi.wgjlcData.service.IDataWgjlcChwqdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;


/**
 * 无轨胶轮车常温启动测试项Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-27
 */
@Service
public class DataWgjlcChwqdServiceImpl implements IDataWgjlcChwqdService
{
    @Autowired
    private DataWgjlcChwqdMapper dataWgjlcChwqdMapper;

    /**
     * 查询无轨胶轮车常温启动测试项
     * 
     * @param chwqdId 无轨胶轮车常温启动测试项主键
     * @return 无轨胶轮车常温启动测试项
     */
    @Override
    public DataWgjlcChwqd selectDataWgjlcChwqdByChwqdId(Long chwqdId)
    {
        return dataWgjlcChwqdMapper.selectDataWgjlcChwqdByChwqdId(chwqdId);
    }

    /**
     * 查询无轨胶轮车常温启动测试项列表
     * 
     * @param dataWgjlcChwqd 无轨胶轮车常温启动测试项
     * @return 无轨胶轮车常温启动测试项
     */
    @Override
    public List<DataWgjlcChwqd> selectDataWgjlcChwqdList(DataWgjlcChwqd dataWgjlcChwqd)
    {
        return dataWgjlcChwqdMapper.selectDataWgjlcChwqdList(dataWgjlcChwqd);
    }

    /**
     * 新增无轨胶轮车常温启动测试项
     * 
     * @param dataWgjlcChwqd 无轨胶轮车常温启动测试项
     * @return 结果
     */
    @Override
    public int insertDataWgjlcChwqd(DataWgjlcChwqd dataWgjlcChwqd)
    {
        dataWgjlcChwqd.setCreateTime(DateUtils.getNowDate());
        return dataWgjlcChwqdMapper.insertDataWgjlcChwqd(dataWgjlcChwqd);
    }

    /**
     * 修改无轨胶轮车常温启动测试项
     * 
     * @param dataWgjlcChwqd 无轨胶轮车常温启动测试项
     * @return 结果
     */
    @Override
    public int updateDataWgjlcChwqd(DataWgjlcChwqd dataWgjlcChwqd)
    {
        dataWgjlcChwqd.setUpdateTime(DateUtils.getNowDate());
        //list转Json字符串
        if(!dataWgjlcChwqd.getTestChwqdList().isEmpty()) {
            dataWgjlcChwqd.setDataList(JSON.toJSONString(dataWgjlcChwqd.getTestChwqdList()));
        }
        return dataWgjlcChwqdMapper.updateDataWgjlcChwqd(dataWgjlcChwqd);
    }

    /**
     * 查询无轨胶轮车-常温启动测试项
     *
     * @param dataTaskId
     * @return 无轨胶轮车-常温启动测试项
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataWgjlcChwqd>> selectDataWgjlcChwqdByDataTaskId(Long dataTaskId) {
        List<DataWgjlcChwqd> dataWgjlcChwqdEntities = dataWgjlcChwqdMapper.selectDataWgjlcChwqdByDataTaskId(dataTaskId);
        if (dataWgjlcChwqdEntities.size() != 0) {
            dataWgjlcChwqdEntities.forEach(item -> {
                if (item.getDataList() != null && item.getDataList().length() != 0) {
                    item.setTestChwqdList(JSON.parseArray(item.getDataList(), TestChwqd.class));
                    item.setListSize(item.getTestChwqdList().size());
                }
            });
        }
        return new AsyncResult<>(dataWgjlcChwqdEntities);
    }

    /**
     * 修改状态为2
     *
     * @param dataTaskId
     */
    @Override
    public int updateDataWgjlcChwqdByDataTaskId(Long dataTaskId) {
        return dataWgjlcChwqdMapper.updateDataWgjlcChwqdByDataTaskId(dataTaskId);
    }


    /**
     * 批量新增无轨胶轮车-常温启动测试项
     *
     * @param dataWgjlcChwqd 无轨胶轮车-常温启动测试项
     * @return 结果
     */
    @Override
    public int batchDataWgjlcChwqd(List<DataWgjlcChwqd> dataWgjlcChwqd) {
        return dataWgjlcChwqdMapper.batchDataWgjlcChwqd(dataWgjlcChwqd);
    }

    /**
     * 批量删除无轨胶轮车常温启动测试项
     * 
     * @param chwqdIds 需要删除的无轨胶轮车常温启动测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcChwqdByChwqdIds(Long[] chwqdIds)
    {
        return dataWgjlcChwqdMapper.deleteDataWgjlcChwqdByChwqdIds(chwqdIds);
    }

    /**
     * 删除无轨胶轮车常温启动测试项信息
     * 
     * @param chwqdId 无轨胶轮车常温启动测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcChwqdByChwqdId(Long chwqdId)
    {
        return dataWgjlcChwqdMapper.deleteDataWgjlcChwqdByChwqdId(chwqdId);
    }
}
